package com.example.thornchg.yc_plane_game.enemy;

import com.example.thornchg.yc_plane_game.R;

import org.cocos2d.actions.instant.CCHide;
import org.cocos2d.actions.interval.CCMoveTo;
import org.cocos2d.actions.interval.CCSequence;
import org.cocos2d.layers.CCLayer;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.sound.SoundEngine;

import java.util.Random;

public class Enemy_1 extends Enemy {
    private Random random;

    public Enemy_1() {
        super("enemy/enemy1.png",100,4,
                "enemy/enemy1_down%d.png");
        setScore(100);
        random=new Random();
        setStartPosition();




        move();
    }

    @Override
    public void playDeadEffect() {
        SoundEngine.sharedEngine().playEffect(CCDirector.theApp, R.raw.enemy1_dead);
    }

    @Override
    public void move() {
        CCMoveTo ccMoveTo = CCMoveTo.action(3f, CCLayer.ccp(getPosition().x, -getBoundingBox().size.getHeight()));
        CCHide ccHide = CCHide.action();
        CCSequence ccSequence = CCSequence.actions(ccMoveTo, ccHide);
        runAction(ccSequence);
    }

    @Override
    public void setStartPosition() {
        float x = random.nextFloat() * (winSize.getWidth() - 40) + 20;
        setPosition(CCLayer.ccp(x, winSize.getHeight()));
    }
}
